
package com.shop.cloud.mall.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cloud.mall.api.service.OrderInfoService;
import com.shop.cloud.mall.common.constant.MallConstants;
import com.shop.cloud.mall.common.entity.OrderBill;
import com.shop.cloud.mall.api.mapper.OrderBillMapper;
import com.shop.cloud.mall.api.service.OrderBillService;
import com.shop.cloud.mall.common.entity.OrderInfo;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单发票
 *
 * @author
 * @date 2023-04-14 11:06:56
 */
@Slf4j
@Service
@AllArgsConstructor
public class OrderBillServiceImpl extends ServiceImpl<OrderBillMapper, OrderBill> implements OrderBillService {

	private final OrderInfoService orderInfoService;

	@Override
	@Transactional(rollbackFor = Exception.class)
	public boolean save(OrderBill entity) {
		OrderInfo orderInfo = orderInfoService.getById(entity.getOrderId());
		entity.setBillAmount(orderInfo.getPaymentPrice());
		entity.setBillStatus(MallConstants.BILL_STATUS_1);
		entity.setShopId(orderInfo.getShopId());
		entity.setOrderId(orderInfo.getId());
		baseMapper.insert(entity);
		return Boolean.TRUE;
	}
}
